﻿using System.Linq;
using SubsidiosBussinessLogic.DataAccess.Interfaces;
using SubsidiosBussinessLogic.Models;

namespace SubsidiosBussinessLogic.DataAccess.SqlServerRepository
{
    public class BeneficiarioRepository : EnteRepository, IBeneficiarioRepository
    {
        #region Miembros de IBeneficiarioRepository

        public BeneficiarioRepository(IDataContextFactory dataContext) : base(dataContext)
        {
        }

        public IQueryable<Beneficiario> GetBeneficiarios()
        {
            return DataContextFactory.Context.GetTable<Beneficiario>();
        }

        public Beneficiario CreateBeneficiario()
        {
            var ente = CreateEnte();
            var beneficiario = new Beneficiario {Ente = ente};
            DataContextFactory.Context.GetTable<Beneficiario>().InsertOnSubmit(beneficiario);
            return beneficiario;

        }

        public void DeleteBeneficiario(Beneficiario beneficiario)
        {
            DeleteEnte(beneficiario.Ente);
            SaveAll();
        }

        public void SaveBeneficiario()
        {
            SaveEnte();
            SaveAll();
        }

        #endregion
    }
}